home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d7 / commdrvr.arc / TTY.ASM < prev    next >
Assembly Source File  |  1988-04-11  |  4KB  |  157 lines

  1.         page    60,132
  2. ;***********************************************************
  3. ;**     TTY Program to Test the RS232 Device Driver       **
  4. ;**     Author: Greg Haley                                **
  5. ;***********************************************************
  6.         name    tty
  7.         title   Interrupt Driven TTY Program
  8.  
  9. cr        equ    13
  10. lf        equ    10
  11.  
  12. console_io    equ    6
  13. aux_in        equ    3fh
  14. aux_out        equ    4
  15. print_string    equ    9
  16. aux_handle    equ    3
  17. write_control    equ    4403h
  18. read_control    equ    4402h
  19. terminate       equ     4c00h
  20. msdos           equ     21h
  21.  
  22. code    segment 
  23.         assume  cs:code, ds:code, ss:code
  24.         org     100h
  25.  
  26. tty     proc    near
  27. start:
  28.         jmp     go
  29.  
  30. ;***********************************************************
  31. ;**     Variables                                         **
  32. ;***********************************************************
  33.         db      40 dup (?)              ; Stack
  34. t_stack db      0
  35. connect db      0                       ; Connect flag
  36. r_len    dw    0            ; Receive buffer length
  37. DCB    db    01000101b        ; LEN, raise DTR
  38. DCW    dw    1100000001000000b    ; Port 1, 1200, 8N1
  39. off    db    0            ; Drop DTR & reset driver
  40. buffer    db    ?            ; Storage for char read
  41.  
  42. init_msg:
  43.     db    'TTY emulation begun.'
  44.     db    cr,lf,'Press any function key to exit.',cr,lf,lf,'$'
  45.  
  46. dcb_error:
  47.     db    cr,lf,'Error writing DCB.$'
  48.  
  49. off_error:
  50.     db    cr,lf,'Error disconnecting.$'
  51.  
  52. dcw_error:
  53.     db    cr,lf,'Error writing DCW.$'
  54.  
  55. len_error:
  56.     db    cr,lf,'Error reading receive buffer length.$'
  57.  
  58. ;***********************************************************
  59. ;**     Program starts here                               **
  60. ;***********************************************************
  61. go:
  62.         mov     sp,offset t_stack
  63.  
  64. ; print signon msg
  65.     mov    dx,offset init_msg
  66.     mov    ah,print_string
  67.     int    msdos
  68.  
  69. ;***********************************************************
  70. ;**     Initialize the driver                             **
  71. ;***********************************************************
  72. ; Send DCB to driver, AUX is already open
  73.     mov    bx,aux_handle
  74.     mov    dx,offset DCB
  75.     mov    cx,1
  76.     mov    ax,write_control
  77.     int    msdos
  78.     jnc    DCB_ok
  79.     mov    dx,offset dcb_error    ; If error print msg & exit
  80.     mov    ah,print_string
  81.     int    msdos
  82.     jmp    exit
  83. DCB_ok:
  84.  
  85. ; Send DCW to driver
  86.     mov    dx,offset DCW
  87.     mov    cx,2
  88.     mov    ax,write_control
  89.     int    msdos
  90.     jnc    DCW_ok
  91.     mov    dx,offset dcw_error    ; If error print msg & exit
  92.     mov    ah,print_string
  93.     int    msdos
  94.     jmp    exit
  95. DCW_ok:
  96.  
  97.     mov    byte ptr connect,1    ; Set connect flag
  98.  
  99. ;***********************************************************
  100. ;**     Main Comm Routine                                 **
  101. ;***********************************************************
  102. wait4chr:
  103.         cmp     byte ptr connect,0      ; Are we on-line?
  104.         jz      exit                    ; No, exit
  105.  
  106. ; Read 1 char from AUX
  107.     mov    bx,aux_handle
  108.     mov    dx,offset buffer
  109.     mov    cx,1
  110.         mov     ah,aux_in               ; Yes, read & display char
  111.         int     msdos
  112.     
  113. ; Check for keyboard input
  114.         mov     dl,0ffh                 ; Is a char ready at keyboard?
  115.         mov     ah,console_io
  116.         int     msdos
  117.         jc      wait4chr                ; No, loop again (DOS 2.xx)
  118.         jz      wait4chr                ; No, loop again (DOS 3.xx)
  119.                                         ;   (Why did Microsoft change???)
  120.  
  121.         or      al,al                   ; Yes, was it a null of F-key?
  122.         jnz     send_char               ;   No, send char
  123.     mov    byte ptr connect,0    ;   Yes, disconnect
  124.         mov     dl,0ffh                 ;   Read 2nd half of F-Key
  125.         mov     ah,console_io
  126.         int     msdos
  127.     jmp    short exit        ; and exit
  128.  
  129. ; Send a char to AUX
  130. send_char:
  131.         mov     dl,al                   ; No, send char
  132.         mov     ah,aux_out
  133.     int    msdos
  134.         jmp     short wait4chr
  135.  
  136. ;***********************************************************
  137. ;**     Disconnect and reset the driver                   **
  138. ;***********************************************************
  139. exit:
  140.     mov    bx,aux_handle
  141.     mov    dx,offset off
  142.     mov    cx,1
  143.     mov    ax,write_control
  144.     int    msdos
  145.     jnc    off_ok
  146.     mov    dx,offset off_error    ; If error print msg & exit
  147.     mov    ah,print_string
  148.     int    msdos
  149. off_ok:
  150.  
  151.         mov     ax,terminate            ; Terminate program
  152.         int     msdos
  153.  
  154. tty     endp
  155. code    ends
  156.         end start
  157.